package com.pfzy.utildemo.activity.im;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.pfzy.utildemo.ConstsValue;

import org.jetbrains.annotations.NotNull;

import java.util.List;

public class MessageListAdapter2 extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    private Context mContext;
    private List<Message> list;

    public MessageListAdapter2(Context context, List<Message> list) {
        this.list = list;
        this.mContext = context;
    }

    @Override
    public int getItemViewType(int position) {
        return this.list.get(position).getType();
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        if (viewType == ConstsValue.MESSAGE_TYPE_SEND) {// 类型 标题
            return new SendMessageViewHolder(new SendMessageView(parent.getContext()));
        } else if (viewType == ConstsValue.MESSAGE_TYPE_RECEIVE) {// 类型 内容
            return new ReceiveMessageViewHolder(new ReceiveMessageView(parent.getContext()));
        }
        return null;
    }

    @Override
    public void onBindViewHolder(@NonNull @NotNull RecyclerView.ViewHolder holder, int position) {
        if (list.get(position).getType() == ConstsValue.MESSAGE_TYPE_SEND) {
            SendMessageView view = (SendMessageView) holder.itemView;
            view.bindView(list.get(position));
        } else {
            ReceiveMessageView view = (ReceiveMessageView) holder.itemView;
            view.bindView(list.get(position));
        }
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    public class SendMessageViewHolder extends RecyclerView.ViewHolder {
        public SendMessageViewHolder(View view) {
            super(view);
        }
    }

    public class ReceiveMessageViewHolder extends RecyclerView.ViewHolder {
        public ReceiveMessageViewHolder(@NonNull @NotNull View itemView) {
            super(itemView);
        }
    }
}
